******************************************************************************************
* Do-file name:	an_dec_employ_02.do                                                      
* Task:         run regressions on non-employment, municipality level      
* Last change:  03.04.2023                                                               
* Notes:
/*
This file contains the code used to generate the results presented in the following tables and figures:
- Table 3:
		-- Displacement effect, Panel A: dec_emp_11
*/                                                                          
******************************************************************************************



******************************************************************************************
*** program setup
******************************************************************************************

version 14.2
clear all
macro drop _all
set linesize 90
set more off
* set trace on
discard
set seed 123456789
*set matsize 2000



******************************************************************************************
*** load working dataset
******************************************************************************************

use "data/employ_region_s2.dta", clear		// data for regional non-employment



******************************************************************************************
*** set globals
******************************************************************************************

* 1) 
global sample_non_emp "All non-employed workers (natives)"
global weight "non_emp_nat_90*weight_matching"
global dcomp  "dec_emp_11"


*** use different czech shocks
foreach year of numlist 1985/1990 1992/1995 {
global czech_shock_`year' "czshare_92_90_predic_13"
	}

global czech_shock_1991   "czshare_91_90_predic_13"



******************************************************************************************
*** estimate employment change
******************************************************************************************

*** run different outcome variables
foreach var of global dcomp {

foreach y of numlist 1993/1995 {

*** 1) basic model: full sample
reg `var'  ${czech_shock_`y'}  if year == `y' & (border_imp_13 == 1 | control_imp == 1) [pweight=${weight}], cluster(ao_kreis_imp)
est store `var'`y'


*** check sample
dis "Sample: ${sample_non_emp}"
dis "Outcome Variable: `var'"
dis "Estimation weight: ${weight}" 
dis "Year = `y'"
dis "Sample restriction version: 16-65, non-employed natives in region"
count if e(sample)


********* bootstrap standard errors ***************************************************************
preserve
keep if e(sample)
drop czshare_92_90_predic_13
forval bs = 1/500 {
	di "bootstrap sample `bs'"
	merge m:1 ao_gem_imp using "data/bootstrap/bs_wild_first_92_`bs'.dta", nogenerate
	reg `var'  czshare_92_90_predic_13  if year == `y' & (border_imp_13 == 1 | control_imp == 1) [pweight=${weight}]
	predict res  if e(sample), res
	predict xb   if e(sample), xb
	gen y = xb + wild * res
	qui reg y  czshare_92_90_predic_13  if year == `y' & (border_imp_13 == 1 | control_imp == 1) [pweight=${weight}]
	scalar coef`bs' = _b[czshare_92_90_predic_13]
	drop y res xb czshare_92_90_predic_13 wild
}
gen bs = . 
gen coef_`var'_`y' = .
forval bs = 1/500 {
	replace bs = `bs' in `bs'
	replace coef_`var'_`y' = coef`bs' in `bs'
}
keep bs coef_`var'_`y'
keep if bs != .
save "data/bootstrap/non_emp/bs_`var'_`y'.dta", replace
sum				// std. dev. = std. error
restore

***************************************************************************************************
	}


*** create tables
#delimit ;
global estout_employ "cells(b(star fmt(%9.3f) vacant(-)) se(fmt(%9.3f) par)) 
stats(N N_clust r2_a, labels("Observations" "Clusters" "Adjusted R2") layout(@ @ @) fmt(%9.0fc %9.0fc %9.3f))
starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30)
varlabels(_cons "Constant" czshare_92_90_predic_13 "Share Czechs (92-90, pred.)" czshare_91_90_predic_13 "Share Czechs (91-90, pred.)") label
mlabels("Empl. 93-90" "Empl. 94-90" "Empl. 95-90")
prehead(@title) posthead() postfoot(@note) nonumbers collabels(none) style(tab)";
#delimit cr


** Table: Employment
sum obs_1990
local obs_1990 = r(mean)

estout  `var'1993  `var'1994  `var'1995 ///
using "tables\employ/tab_`var'.txt", $estout_employ replace ///	
title(Employment Growth for Non-Employed Workers: `var' (1993-1995): Base, Sample: ${sample_non_emp}) ///
note(Notes: Regional approach, non-employ. workers. * p<0.1, ** p<0.05, *** p<0.01. Obs. 1990: `obs_1990'. ///
Data Source: German Social Security Records, border districts and matched control districts, 1993-1995.)
	}


******************************************************************************************
*** end
******************************************************************************************

exit


*========================================================================================*
Comments:
- unique identifier: vsnr_ano year
